package com.best.onegous.Adapter;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.best.onegous.R;
import com.best.onegous.View.MyDialog;
import com.best.onegous.agreement.Apps;
import com.best.onegous.agreement.Common;
import com.best.onegous.details.User;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class IndianarecordsAdapter extends BaseAdapter {
	Intent intent;
	private List<JSONObject> data = new ArrayList<JSONObject>();
	private LayoutInflater layoutInflater;
	private Context context;

	public IndianarecordsAdapter(Context context, List<JSONObject> data) {
		this.context = context;
		this.data = data;
		this.layoutInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub

		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub

		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHome viewhome = null;
		if (convertView == null) {
			viewhome = new ViewHome();
			convertView = layoutInflater.inflate(R.layout.indianarecords_item,
					null);
			 viewhome.userimg = (ImageView) convertView.findViewById(R.id.userimg);
			 viewhome.name = (TextView) convertView.findViewById(R.id.name);
			 viewhome.goumai = (TextView) convertView.findViewById(R.id.goumai);
			 viewhome.time = (TextView) convertView.findViewById(R.id.time);
			 
			convertView.setTag(viewhome);
		} else {
			viewhome = (ViewHome) convertView.getTag();
		}

		JSONObject item = data.get(position);
		try {
			Apps.imageLoader.displayImage(Common.PHOTOURL+item.getString("uphoto"), viewhome.userimg, Apps.touxiang);
			viewhome.name.setText(item.getString("username"));
			viewhome.goumai.setText("参与多宝("+item.getString("gonumber")+")次");
			viewhome.time.setText(item.getString("time"));
			
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return convertView;
	}

	class ViewHome {
		private ImageView userimg;
		private TextView name,goumai,time;
	}

}